Binding C functions to LUA
I want to bind C functions to lua script system, but without using tolua or similar, anyone have some tutorial?
I''ve recently finished three tutorials on Lua. Go to http://tonyandpaige.com/tutorials/ for a list of them.
Also, I''d appreciate any feedback on these tutorials.
Tony
Also, I''d appreciate any feedback on these tutorials.
Tony
yes this part of the reference manual I have read it, but my problem is that I don''t know how to bind any function, not only a function prepared to use in lua with the lua_state parameter ...
I have other question too, if I have a win32 console application, and I want to read the input user with scanf/cin, and this input execute a C function bind to lua, or a lua command, how to do this?.
I have other question too, if I have a win32 console application, and I want to read the input user with scanf/cin, and this input execute a C function bind to lua, or a lua command, how to do this?.
Create a helper function that will pop the arguments off the stack and pass them to the real function, then push the return value onto the stack and return. Then register the helper function.
I don''t really understand the grammar in your second question. Try again.
How appropriate. You fight like a cow.
I don''t really understand the grammar in your second question. Try again.
How appropriate. You fight like a cow.
sorry for my english
I''ll try again:
I want to make a lua-like console, in a win32-console app, for example, if user types myfunc, I read the string "myfunc" with scanf/cin... and my program executes the C function myfunc, and if the user types print("hi");, the program executes the lua function print with arg "hi", or the user types: exec file.lua and the program execute the file.lua.
I''ll try again:
I want to make a lua-like console, in a win32-console app, for example, if user types myfunc, I read the string "myfunc" with scanf/cin... and my program executes the C function myfunc, and if the user types print("hi");, the program executes the lua function print with arg "hi", or the user types: exec file.lua and the program execute the file.lua.
Are you using Lua 4 or Lua 5? In Lua 4, there''s a "dostring" command, which you would probably find helpful. I forget the analogue from Lua 5, but there is one.
How appropriate. You fight like a cow.
How appropriate. You fight like a cow.
lua_register(state, name, func);
This should do the job. Make your function, give it a name and state then register it. For objects its a little more complex, but essentially you can create a table and insert methods or properties.
I can provide a link to some source if need be.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement