lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Like this, you say?

int a;

-- CODE/ --

// Open Lua and its libraries
lua_State *L = lua_open();
luaL_openlibs(L);

// Add all arguments
for (a = 0; a < argc; a++)
	lua_pushstring(L, argv[a]);

// Run!
if (luaL_loadbuffer(L,(const char*)B1,sizeof(B1),"mtx.luc")==0)
	if (lua_pcall(L, 1, 0, 0) != 0)
		puts(lua_tostring(L,-1));

// Close Lua and exit program
lua_close(L);
return 0;

-- /CODE --

That gives me an error: "attempt to call a string value". Call a string value? Isn't the "mtx.luc" part supposed to be just for debugging?

Why is it giving me this? Thanks very much for your help!

Julien Hamaide wrote:
L-28C wrote:
But running it will be a different matter, esp. since you're not
initializing any of the Lua libraries [i.e. no output functions are
available to your Lua script!].
luaL_openlibs(L);

That did the trick. :-)

Eh, I don't even want to ask, but are you using bin2c on C code?
I am a noob, but not of THAT magnitude! xD


Now, I don't think a new thread deserves this, so I'll ask here. How do
you pass arguments to the bin2c'd script?

Thank you all!



Simple push arguments on the stack, and set the number of argument in
lua_pcall. you can use ... to retrieve the arguments inside the script :

arg1, arg2, arg3 = ...