marcolizza / tiny-js Goto Github PK
View Code? Open in Web Editor NEWA simple single-file javascript interpreter written in C++
License: MIT License
A simple single-file javascript interpreter written in C++
License: MIT License
I have tried to compile TinyJS on my Mac, but got:
Script.cpp:50:5: error: use of undeclared identifier 'CTinyJS'; did you mean 'TinyJS'?
CTinyJS *js = (CTinyJS*)userdata;
^~~~~~~
TinyJS
./TinyJS_Functions.h:35:11: note: 'TinyJS' declared here
namespace TinyJS {
^
Script.cpp:50:5: error: unexpected namespace name 'TinyJS': expected expression
CTinyJS *js = (CTinyJS*)userdata;
^
Script.cpp:50:14: error: use of undeclared identifier 'js'
CTinyJS *js = (CTinyJS*)userdata;
^
Script.cpp:50:20: error: use of undeclared identifier 'CTinyJS'; did you mean 'TinyJS'?
CTinyJS *js = (CTinyJS*)userdata;
^~~~~~~
TinyJS
./TinyJS_Functions.h:35:11: note: 'TinyJS' declared here
namespace TinyJS {
^
Script.cpp:50:20: error: unexpected namespace name 'TinyJS': expected expression
CTinyJS *js = (CTinyJS*)userdata;
^
Script.cpp:50:28: error: expected expression
CTinyJS *js = (CTinyJS*)userdata;
^
Script.cpp:51:5: error: use of undeclared identifier 'js'
js->root->trace("> ");
^
7 errors generated.
Should I use -DCTinyJS=TinyJS
, maybe?
Is there a way to get the name of an object? For e.g if i create an object like this
var myBaseObject = {
name: "Test",
value: 3
};
and now i want to get the name of the object myBaseObject
. How can i do that? For e.g i want to write a function to tell me the name of the object
var test = myBaseObject.clone();
var theName = test.getObjectName();
Afterwards the variable theName
should output myBaseObjetct
.
Is that possible?
auto jsEngine = make_unique<CTinyJS>();
registerFunctions(jsEngine.get());
string js = "String('ape katt').split(' ');";
jsEngine->execute(js);
==> Error Expecting 'String' to be a function
commit db198df
Error details (console output)
make g++ -c -g -Wall -rdynamic -D_DEBUG run_tests.cpp -o run_tests.o g++ -c -g -Wall -rdynamic -D_DEBUG TinyJS.cpp -o TinyJS.o g++ -c -g -Wall -rdynamic -D_DEBUG TinyJS_Functions.cpp -o TinyJS_Functions.o g++ -c -g -Wall -rdynamic -D_DEBUG TinyJS_MathFunctions.cpp -o TinyJS_MathFunctions.o g++ -g -rdynamic run_tests.o TinyJS.o TinyJS_Functions.o TinyJS_MathFunctions.o -o run_tests g++ -c -g -Wall -rdynamic -D_DEBUG Script.cpp -o Script.o Script.cpp: In function ‘void js_dump(TinyJS::Variable*, void*)’: Script.cpp:50:5: error: ‘CTinyJS’ was not declared in this scope CTinyJS *js = (CTinyJS*)userdata; ^~~~~~~ Script.cpp:50:14: error: ‘js’ was not declared in this scope CTinyJS *js = (CTinyJS*)userdata; ^~ Script.cpp:50:28: error: expected primary-expression before ‘)’ token CTinyJS *js = (CTinyJS*)userdata; ^ Makefile:21: recipe for target 'Script.o' failed make: *** [Script.o] Error 1
Solution
replace in file Script.cpp line 50
CTinyJS *js = (CTinyJS*)userdata;
with
TinyJS::Interpreter *js = (TinyJS::Interpreter*)userdata;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.