lua - not getting string!

BlitzMax Forums/BlitzMax Programming/lua - not getting string!

Caton(Posted 2016) [#1]
Local LuaState:Byte Ptr = luaL_newstate()
luaL_openlibs(LuaState)
luaL_loadfile(LuaState,"Game.lua")
lua_getglobal(LuaState, "title")
Print lua_tostring(LuaState, -1)
lua_close(LuaState)



dw817(Posted 2016) [#2]
What the heck ? This actually runs in BlitzMAX ? So BlitzMAX can run LUA code as well ?


grable(Posted 2016) [#3]
What the heck ? This actually runs in BlitzMAX ? So BlitzMAX can run LUA code as well ?
Of course it can, LUA has a pretty simple C api. So does most other scripting languages too for that matter ;)
Though you probably want to use BRL.MaxLua if your going to intermix types and all that...

@Caton
Your just loading the file, not running it. It ends up as a callable function on the stack.
Either call lua_pcall on the value or use luaL_dofile instead.

And you should probably look at the docs if this confuses you, all this is quite well documented.
http://www.lua.org/manual/5.1/manual.htm


Derron(Posted 2016) [#4]
@ dw817
(BTW: checkout the render-to-texture-thread - might be of interest for you)

If you are interested in "MaxLua" I would suggest to use my luaEngine - as it is based on the MaxLua idea but provides some more features (restrict function exposure, blacklisting of lua-modules to avoid making your app become a backdoor of malicious lua scripts, enhanced compatibility for blitzmax-lua-objects like "nil vs null")

https://github.com/GWRon/Dig/blob/master/samples/lua/lua.bmx
https://github.com/GWRon/Dig/blob/master/base.util.luaengine.bmx


bye
Ron