Read LUA File
BlitzMax Forums/BlitzMax Programming/Read LUA File
| ||
Hello! I can't seem to figure out why this isn't working.... bmx file Global state:Byte Ptr = luaL_newstate() Global width:Int Global height:Int Load(state, "graphics.lua") Function Load(State:Byte Ptr, FileName:String) If luaL_loadfile(State, FileName) lua_pcall(State, 0, 0, 0) If lua_error(State) Notify "Error Dude!" End End If width:Int = lua_getglobal(State, "Width") height:Int = lua_getglobal(state, "Height") Notify "Width: " + width + "Height: " + height Else Notify "Failed to Load" End If End Function graphics.lua file --Set Graphics Width = 800 Height = 600 |
| ||
Just so you know, lua_error causes an error to be created, it doesn't check for errors. Also, luaL_loadfile will return zero on success, so your conditional will only go through if there's an error, at which point you definitely shouldn't be using pcall on whatever's on the stack. I would recommend reading the manual, because it seems like you're just looking at function names and guessing, for the most part. |
| ||
Oh wow you're right. I am actually reading the Manual, it's just all in C so it's a little confusing, but it's coming along, Thanks ;) |