...but when when you have time could you explain why the order is that that? It seems to be jumbled and when you set "varname" value as the table you don't actually provide "varname" so how does it know?
"varname" is provided via the lua_pushstring that pushes "varname" (the key into the globals table) onto the stack. Whenever you modify a table, you have to at the least push a key onto the stack (for get and set).
Because all global variables are stored in the globals table, you have to push the variable name and then the value of the variable, then call lua_settable with the globals table constant (LUA_GLOBALSINDEX).
If varname doesn't exist in the globals table, it will be added to the table upon calling lua_settable.
if I passed a table from lua to a blitz function how would I get things from it?
Basically the same process:
' Push the key onto the stack lua_pushstring( st, "key" ) ' Tell lua to get the value from the table and push it onto the stack (it will still be in the table) -- it automatically pops the key lua_gettable( st, stack index ) ' Get the value that was pushed onto the stack value = lua_tostring/tonumber/toboolean( st, -1 ) ' Remove the popped value from the stack lua_pop( st, 1 )
is it possible to run a specific function in a lua file from blitz?
Yes.
lua_pushstring( st, "function name" ) lua_gettable( st, LUA_GLOBALSINDEX ) ' push any arguments onto the stack ' call the function Local err:Int = lua_pcall( st, numargs, numresults, 0 or an error handler function index ) ' get any results -- if err is <> 0 then the pushed result will be an error message (string)