Hi
Thanks a lot. Referring your links I could do a small test program. However I am not able to get the output of lua function in C code. Here is my example code. Please let me know, how to collect the lua function output in C code. After I call lua_loadstring, I want to print function output in Code.., please let me know how to do it...
#include <lua5.2/lauxlib.h>
#include <lua5.2/lualib.h>
int main (void) {
char *data[8] = {
"function fact (n)",
"if n==0 then",
"return 1",
"else",
"return n * (fact(n-1))",
"end",
"end" /*,
"print (\"Factorial: \",fact(4))" */
};
char buffer[512];
int error;
int index = 0;
int offset = 0;
lua_State *L = luaL_newstate(); /* opens Lua */
luaopen_base(L); /* opens the basic library */
luaopen_string(L); /* opens the string lib. */
luaopen_math(L); /* opens the math lib. */
while(index < 9)
{
offset += sprintf((buffer+offset), "%s\n", data[index]);
index++;
}
buffer[offset] = 0;
//printf("string = %s", buffer);
luaL_dostring(L, buffer);
lua_close(L);
return 0;
}