Created
January 1, 2016 10:13
-
-
Save yihuang/63290daa3e2fb607fee2 to your computer and use it in GitHub Desktop.
test lua intf, return pointer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "LuaIntf/LuaIntf.h" | |
| using namespace LuaIntf; | |
| void* test_malloc(int n) { | |
| return malloc(n); | |
| } | |
| void test_free(void* p) { | |
| free(p); | |
| } | |
| void open(lua_State* L) { | |
| LuaBinding(L).beginModule("test") | |
| .addFunction("malloc", &test_malloc) | |
| .addFunction("free", &test_free) | |
| .endModule(); | |
| } | |
| int main() { | |
| LuaContext ctx; | |
| open(ctx.state()); | |
| ctx.doString("test.free(test.malloc(10))"); | |
| } | |
| // $ clang++ -std=c++11 test.cpp -llua | |
| // $ ./a.out | |
| // libc++abi.dylib: terminating with uncaught exception of type LuaIntf::LuaException: [string "test.free(test.malloc(10))"]:1: bad argument #-1 to 'malloc' (table expected, got nil) | |
| [1] 12892 abort ./a.out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could define a LuaTypeMapping<void *> class, and create a lua table that contains low and high part of void *(consider 64bit platforms) in the push method.