Comments (6)
You could obtain "function pointers" from the script using getValueId. BUT the function could be freed by OS garbage collector so you have to retain the function using retainValueById and release it (see releaseValueById) when you don't want to use the function.
You could put saved function to OS stack using pushValueById.
You could make value as permanent using retainValueById.
You could obtain other types as permanent values using the same way. Numbers, booleans and null are simple types. They have no id so you should save them as is (see toNumber, toFloat, toBool and so on).
The Core class is used internally. There are a lot of low end operations inside of the core. So programmer have to use the core carefully, it could be not simple. I was trying to implement general API functions inside of OS class so you should not use the core usually. You could use core's types and functions if you know what you do.
Feel free to ask me any questions.
from objectscript.
:) https://github.com/IngwiePhoenix/ObjectScriptValue
I'm on it. This shouldn't be too hard. I just started it, like, half a hour ago...
The idea is to mimic the life cycle of variables. So when the instance goes out of scope, the associated value does too. (see destructor).
I was wondering how I could make function calling easy, to support types. But first I need to get objects and such to work for real. I have only tested things using test.cpp
so far. If you have any suggestions while I am at it, go ahead! I'll try to make it as compliant as possible, so it can be put into any OS projects.
from objectscript.
Im stuck at the getter. I know how to get Object properties with strings:
case OS_VALUE_TYPE_OBJECT:
myOS->pushValueById(valueID);
myOS->getProperty(index);
char* str = (char*)(myOS->toString().toChar());
myOS->pop();
return str;
But how do I access array elements with a numeric index? I.e.: arr[2]
from objectscript.
Awesome, you work very hard!
I've reviewed your OSValue.cpp, it seems like you need to upgrade OS version, there is no OS_VALUE_TYPE_UNKNOWN in ObjectScript at the moment. The latest version is ObjectScript 2.3.8-rc.
You could obtain a value from array as follows:
case OS_VALUE_TYPE_ARRAY:
myOS->pushValueById(valueID);
myOS->pushNumber(numIndex); // index of value
/* Obtain string value from array... */
myOS->getProperty();
return myOS->popString();
The same way works for objects:
case OS_VALUE_TYPE_OBJECT:
case OS_VALUE_TYPE_USEDDATA:
case OS_VALUE_TYPE_USERPTR:
myOS->pushValueById(valueID);
myOS->pushString(strIndex); // string index of value
// or myOS->pushNumber(numIndex); // number index of value
myOS->getProperty();
/* Obtain string value from object */
return myOS->popString();
// or obtain number value from object
// return myOS->popNumber();
Note that OS's garbage collector frees unused values so you should retain (add a reference) value used by your own code or copy it. Be carefull using strings. You can use OS::String type as string value in your own code. OS::String retains string value already. Or copy string using std::string for example.
So your code is not safe
char* str = (char*)(myOS->toString().toChar());
myOS->pop();
change it to
return myOS->popString();
or to
return std::string((char*)(myOS->popString().toChar());
P.S.
OS_VALUE_TYPE_USEDDATA and OS_VALUE_TYPE_USEDPTR works like object but they created from C++ objects, for example DateTime is userdata really.
from objectscript.
Thanks! I will adapt that right in.
Yep, I work hard if I am focused on something. I am making this extension out of personal need for being able to store references to script functions later on.
In the constructor, I am already calling retainById in order to keep the object in cycle. On destruction, the value is freed accordingly.
My goal is to make an "almost complete" wrapper for the script types, so that its easier for C++ code to store them - like I need to store functions an dobjects; actually, the entire object contianing a function.
I was using a version of OS that I had downloaded at some point, will re-clone to have a properly updated header file. Thanks for the tipp. =)
from objectscript.
There goes. I now am going to implement numeric array access, accessing strings by number, etc. Shall be interesting! :)
After that, I think I can move on to setters. If an object has been declared (newObject, newArray), and then the Value instance was made, it should be able to also add values to the respective values. That is more like a little gimmick so I can later modify the object from within my code.
After that, I need to find a good way to implement calling functions, or just making a function to put the function into the stack...
But yeah, this little extension should be done soon! :)
from objectscript.
Related Issues (20)
- целые числа HOT 5
- Just an educational question HOT 7
- Make MySQL optional HOT 1
- Some OS X fixes HOT 4
- $ operator example! HOT 4
- malloc.h still not found :)
- Crash on launch HOT 3
- Need help for an implementation
- C++ embedding questions HOT 14
- Syntactical question HOT 2
- Binding function-local variable to returned lambda function HOT 2
- Accessing object properties HOT 2
- Convenience types and methods HOT 1
- OS::setGlobal(FuncDef *) ? HOT 2
- The OS::call*() functions
- Cannot compile on Mageia 4 HOT 3
- os-fcgi: process.cwd() returning nothing...
- OS::create() should use template in dynamic cast
- Can not serialize the debug backtrace?
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 objectscript.