How to load seprate .so module in js program

35 views
Skip to first unread message

sachin Chaudhary

unread,
Apr 9, 2013, 7:04:20 AM4/9/13
to jsl...@googlegroups.com
hi all 

can any tell how i will be able to add a  .so module to javascript program

******************* foo.h ***************

#ifndef foo_h__
#define foo_h__
 
extern void foo(void);
 
#endif  // foo_h__

******************** foo.c ************


#include <stdio.h>
 
 
void foo(void)
{
    puts("Hello, I'm a shared library");
}


now i make jsfoo.so 

and using LoadModule  try to load this module in js program just to call c function in javascript

var loadModule = host.loadModule;

loadModule('jsfoo');
loadModule('jsstd');
var msg=foo();

print(msg);


now i run this file with  jshost then this throws error  " InternalError: module 'jsfoo.so' fails to initialize "

can anyone tell me the procedure to add seprate .so to js program i am using fedora13

thanks in advance
 


soubok

unread,
Apr 9, 2013, 7:58:02 AM4/9/13
to jslibs
Hello Sachin,
If you want to create a new module, I recommend you to have a look at the module template (jslibs/src/jslibs_module_template).
For more complete example, you can also have a look at existing modules like jsstd. The file jslibs/src/jsstd/static.cpp show you how to expose simple c/c++ functions to the JavaScript engine.

eg.
******************** foo.c ************
#include "stdafx.h"
#include <jslibsModule.h>
#include <stdio.h>

DEFINE_FUNCTION( foo ) {

puts("Hello, I'm a shared library");
// ...
return JS_TRUE;
}

CONFIGURE_STATIC
BEGIN_STATIC_FUNCTION_SPEC
FUNCTION_ARGC( foo, 0 )
END_STATIC_FUNCTION_SPEC
END_STATIC


HIH,
Franck.



 


--
--
Group jslibs - http://groups.google.com/group/jslibs - jsl...@googlegroups.com
Unsubscribe: jslibs-un...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "jslibs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jslibs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

sachin Chaudhary

unread,
Apr 10, 2013, 5:32:27 AM4/10/13
to jsl...@googlegroups.com
Thanks Franck for your response

can you tell me one more thing . how i will be able to take input from console in .js program ( like in c program we take input from console using scanf or gets )

soubok

unread,
Apr 15, 2013, 7:50:23 AM4/15/13
to jslibs
The latest jslibs source code has a  host.stdin()  function that returns a string.
Thanks,
Franck.


sachin Chaudhary

unread,
May 14, 2013, 1:14:01 AM5/14/13
to jsl...@googlegroups.com
thanks frank , for your valuable advice 

i created a test program to call jshost main again and again i created jshost.a and renamed it's main 


there is one problem with jslang when i call jshost 2nd time then that gives segmentation fault....... due to memory leak.

that is due to jslang

that comes when INIT_STATIC() is called inside  jslangmoduleinit from here call goes to 

commons/jlclass.h function 

InitStatic( JSContext *cx, JSObject *obj, ClassSpec *cs ) {


JL_CHK(obj);

printf("cs_static_fs = %x\n",cs->static_fs);

 when i call jslang 2nd time this print gives segmentation fault ......  can you suggest which part need correction ??????????

is Classspec structure pointer creating problem...........






On Tuesday, 9 April 2013 16:34:20 UTC+5:30, sachin Chaudhary wrote:
Reply all
Reply to author
Forward
0 new messages