Skip to main content
GameDev.net gamedev.net
🔒 Locked

lua

Started by huaner Dec 18, 2006 at 4:54 AM 1 replies 1k views
Original Post
huaner
huaner
Hi: there are some questions when I browse the web of lua.the question are: 1.when we call the lua_register(eg: lua_register( luaVM, "addNPC", l_addNPC ); and the file of lua is bleow),its can automaticlly be registered and called by each addNPC(this sample will be called 3 times) 2.when the informations of lua's file are push into stack thans a lot! int l_addNPC( lua_State* luaVM) { theNPCManager->AddNPC( lua_tostring(luaVM, -1) ); lua_pushnumber( luaVM, 0 ); return 1; } addNPC("Joe"); addNPC("Sue"); addNPC("KillBot2000");
blanky
blanky
I think addNPC and theNPCManager are example methods/classes. I doubt they're actually part of Lua, but was used as an example instead. luatostring(luaVM, -1) I think simply takes the string returned by the lua state/virtual machine (I don't know much about this apparently) and turns it into a string that AddNPC can understand. lua_pushnumber I think simply has something to do with sending the information to lua or vice versa, and return 1 means that it returns one value, ... I think, sorry I couldn't be of more help.
kadaf
kadaf
I'm not sure I understand your questions correctly...

Is your first question when you should call lua_register()? If so, the answer is that you should just do it at any point before you execute the Lua script. A good place would probably be when you've just created your Lua virtual machine.

If your second question is how you run the script, you'd either want to load it unto the stack with luaL_loadfile() and then run it with lua_pcall(), or simply call luaL_dofile() on it to both load and run it.
-- Rasmus Neckelmann

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.