I would like to have a detailed explanation.
How would I use the Lua source code to create a Lua interpreter that will execute given blocks of Lua code? The blocks of Lua code would be sent as a char.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
you need a call to
lua_loadto compile the block of code, and then a call tolua_callto run it. For a really good example of how this is done, take a look at the example provided here:.The first argument to any Lua api function is always an interpreter state, which is the return value of
lua_open()The example actually uses
luaL_loadbufferwhich wraps the call tolua_loadto make compiling a c string a bit easier. you can read how to use it in the chapter of the reference manual that covers the The Auxiliary Library. This leaves a lua chunk at the top of the lua stack, which can then be invoked withlua_call, but the example useslua_pcall, which provides a bit of error trapping. since the chunk you just compiled doesn’t take any arguments (it’s a chunk not a function) and doesn’t have any return value you’d be interested in, and you want to see the error exactly as it was produced, all of the arguments besides the first (which is always the lua interpreter state) can be zeros.