Comments (13)
Please show full sources
from v7.
// main.cpp
enum v7_err rcode = V7_OK;
struct v7 *state = NULL;
v7_val_t result;
static void OnUpdate(struct v7 *v7) {
v7_val_t func, result, args;
/* Lookup JavaScript function `sum()` */
func = v7_get(v7, v7_get_global(v7), "Update", 6);
/* Create arguments array with two numbers */
args = v7_mk_null();
/* Call JavaScript function. Pass `undefined` as `this` */
if (v7_apply(v7, func, V7_UNDEFINED, args, &result) == V7_OK) {
printf("Result: %g\n", v7_get_double(v7, result));
}
else {
v7_print_error(stderr, v7, "Error while calling sum", result);
}
}
int main()
{
printf("JavaScript Test");
//V7 start
state = v7_create();
rcode = v7_exec_file(state, "test.js", &result);
if (rcode != V7_OK) {
fprintf(stderr, "exec error: %d\n", (int)rcode);
}
while(1)
{
OnUpdate(state);
}
return 0;
}
from v7.
execute while loop only if v7_exec_file succeeded.
Also, I don't see what's in the test.js
Closing this - as the problem is your code.
from v7.
That's all I've got in Test.js
function Update() {
print("mooo!");
}
@cpq I think the purpose for a post is to help people, instead of closing without having a dialogue
from v7.
I have the same problem under Windows returning a valid JavaScript function v7_var_t with v7_get(). Works fine on Linux and on both asking for non-function vars.
from v7.
I was hoping to include V7 as an extension module with the Script BASIC Windows 32 bit version I'm about to release. It could give Cesanta a bit more exposure. If I can find resolve with v7_get() and JavaScript function name references, I may still be able to slip it in the release.
from v7.
Here is my Linux version that works as expected.
IMPORT js.inc
jscode = """
var sum = function(a, b, c) {
print (c);
return a + b; };
"""
JS::CREATE()
JS::EXEC(jscode)
func = JS::GETS(JS::SYS, "sum")
args = JS::MK_ARRAY()
JS::ARRAY_PUSH(args, JS::MK_NUMBER(123.0))
JS::ARRAY_PUSH(args, JS::MK_NUMBER(0.456))
JS::ARRAY_PUSH(args, JS::MK_STRING("Script BASIC"))
result = JS::APPLY(func, 0, args, rcode)
PRINT FORMAT("Result: %g\n", JS::GET_DOUBLE(result))
JS::DESTROY
jrs@jrs-laptop:~/sb/examples/js$ scriba js_callfunc.sb
Script BASIC
Result: 123.456
jrs@jrs-laptop:~/sb/examples/js$
Here is the Windows version of the same code.
IMPORT js.sbi
jscode = """
var sum = function(a, b, c) {
print (c);
return a + b; };
"""
JS::CREATE()
JS::EXEC(jscode)
func = JS::GETS(JS::SYS, "sum")
args = JS::MK_ARRAY()
JS::ARRAY_PUSH(args, JS::MK_NUMBER(123.0))
JS::ARRAY_PUSH(args, JS::MK_NUMBER(0.456))
JS::ARRAY_PUSH(args, JS::MK_STRING("Script BASIC"))
result = JS::APPLY(func, 0, args, rcode)
PRINT FORMAT("Result: %g\n", JS::GET_DOUBLE(result))
PRINT "Error: ",JS::GET_ERROR(),"\n"
JS::DESTROY
C:\sbsetup\examples>scriba js_callfunc.sb
Result: -1.#QNAN
Error: value is not a function
C:\sbsetup\examples>
from v7.
Here is an example of getting standard (non-function) var references with v7_get() under Windows 32 bit. This same function fails to return a function var reference under Windows only. Works fine under 64 bit Linux. (as stated above)
IMPORT js.inc
jscode = """
var a_int = 64
var a_dbl = 1.23
var a_str = "Script BASIC"
"""
JS::CREATE
JS::EXEC(jscode)
PRINT JS::GET_INT(JS::GETS(JS::SYS, "a_int")),"\n"
PRINT FORMAT("%.2f",JS::GET_DOUBLE(JS::GETS(JS::SYS, "a_dbl"))),"\n"
PRINT JS::GET_STRING(JS::GETS(JS::SYS, "a_str")),"\n"
JS::DESTROY
C:\sbgcc\examples\js>scriba js_getsvar.sb
64
1.23
Script BASIC
C:\sbgcc\examples\js>
from v7.
Here is my debug attempt to find what was going wrong under Windows. I have gone as far as I can trouble shooting this and the problem points to the V7 code.
IMPORT js.inc
jscode = """
var sum = function(a, b) {
return a + b; };
"""
PRINT jscode,"\n"
JS::CREATE()
ok = JS::EXEC(jscode, rcode)
func = JS::GETS(JS::SYS, "sum")
PRINT "func an object? ",JS::IS_OBJECT(func),"\n"
args = JS::MK_ARRAY()
JS::ARRAY_PUSH(args, JS::MK_NUMBER(123.0))
PRINT "args[0] = ",FORMAT("%g",JS::GET_DOUBLE(JS::ARRAY_GET(args, 0))),"\n"
JS::ARRAY_PUSH(args, JS::MK_NUMBER(0.456))
PRINT "args[1] = ",FORMAT("%g",JS::GET_DOUBLE(JS::ARRAY_GET(args, 1))),"\n"
result = JS::APPLY(func, 0, args, rcode)
PRINT "Error: ",JS::GET_ERROR(),"\n"
PRINT "rcode: ",rcode,"\n"
PRINT FORMAT("Result: %g\n", JS::GET_DOUBLE(result))
JS::DESTROY
C:\sbgcc\examples\js>scriba js_callfunc.sb
var sum = function(a, b) {
return a + b; };
func an object? 0
args[0] = 123
args[1] = 0.456
Error: value is not a function
rcode: 2
Result: -1.#QNAN
C:\sbgcc\examples\js>
from v7.
I'm assuming at this point this isn't going to get resolved and I'm wasting my time trying. Sad that something like this kills a project. :-(
from v7.
Yep, it's pretty sad. I replaced my V7 code with dukglue https://github.com/Aloshi/dukglue
from v7.
I'm still pretty bitchy about that guy who closed the thread.
I included everything necessary to the thread and because he don't wanted to spent time reviewing it
properly he closes it. Next time he should just keep quite.
I mean who knows who many people also have this issue and don't look up the closed threads :(
I didn't test my code under Linux, so I can't tell anything about that.
All I can say is that I run Windows 10 64bit and can't get the function call
from v7.
Script BASIC is ANSI C based and I did look at Duktape as an alternative.
I'm pissed all the time I wasted with V7 and the poor attitudes by developers and scanty support. I can't sell my client on using V7 if I can't even sell myself on it.
from v7.
Related Issues (20)
- V7 ScriptBASIC integration on Windows 7 32 bit HOT 41
- unit_test fails HOT 3
- v7_next_prop - No property attributes being returned HOT 10
- Script BASIC HOT 9
- v7.c: line:29703 /* TODO(dfrank) : add getter/setter support */ HOT 1
- How to load the byte code generated by v7_compile? HOT 4
- Make user_data property as _V7_PROPERTY_OFF_HEAP HOT 1
- Problem running a basic test program HOT 2
- Segmentation Faults 2017-05-09
- Can I run under iOS? And Is it thread safe? HOT 2
- v7 support ajax?
- Trouble passing "true", "false" and "null" HOT 3
- v7_array_length issue HOT 1
- link errors since commit 8d8d8ce5... HOT 1
- Developer Centre down?
- C program crashes when trying to retrieve one of struct members as object member if below 0 HOT 4
- v7 Optimization tips
- Linker errors: Undefined symbols for architecture x86_64
- JSON.parse error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from v7.