Lua stuff

BlitzMax Forums/BlitzMax Beginners Area/Lua stuff

dan_upright(Posted 2013) [#1]
I want to use lua for scripting, but I'm having an absolute nightmare working out what's what - there seems to have been umpteen different lua modules since I was last here.

Can anyone give me the lowdown on which is the current "standard" (if there is one) and point me towards the docs?


PhotonTom(Posted 2014) [#2]
Did you ever find an answer to this because i would also quite like to know. LuaJIT module seemed like a good bet but cannot find a live link to the module :S


Wiebo(Posted 2014) [#3]
I like to use LuaJIT by Zeke, and Lugi by Noel Cower. That's all you need to get going! Google for these and you will find the links no problem.


markcw(Posted 2014) [#4]
Zeke's website is gone now, maybe someone will share luaJIT.

Noel's is here https://github.com/nilium/lugi.mod

Then there's Blitzlua by Rozek (which uses axe.lua)
http://lua-users.org/wiki/BlitzLua
http://www.blitzmax.com/Community/posts.php?topic=68845 and http://www.blitzmax.com/Community/posts.php?topic=69530


PhotonTom(Posted 2014) [#5]
Yeah that would be great if someone could share LuaJIT.
Whats the main differences between them? And is one better than the other?
Thanks again for your help :)


Yasha(Posted 2014) [#6]
Huh that's a pity. Was sure I had that archived. Oh well.


To note: there are two major Lua implementations in the wild. Lua proper (i.e. the reference implementation by the authors of the language) is a simple interpreter written in C. It is popular because it is extremely lightweight and extremely portable - very easy to set up. Most people are using this. The builtin Lua module uses this.

The other one is LuaJIT. This is popular because it's nearly as easy to get going as Lua, but is absurdly, insanely fast. LuaJIT knocks the performance socks off even the best JavaScript engines, and gives even medium-quality C compilers a run for their money. It actually produces faster code than BlitzMax itself does, despite "only" being a JIT/interpreter. Think on that for a while: LuaJIT is possibly the only case where you can farm your native code out to the scripting language when you want a performance boost. Many people write whole applications in it as a result.


If you need hardcore performance (reality check: you probably don't actually need much performance from your script engine), you should investigate using the LuaJIT engine even if the premade wrapper doesn't show up again, because the payoff will be immense. Otherwise, do the easy thing.


xlsior(Posted 2014) [#7]
Looks like I had a copy of Zeke's LuaJIT module. Here it is, for the time being:

http://www.xlsior.org/temp/luajit_mods.zip

(Not sure if there is a more recent version, but hey -- better than nothing)


PhotonTom(Posted 2014) [#8]
Thanks so much :)
I've mirrored the file to http://photongamemanager.com/Downloads/luajit_mods.zip and will keep it there until I don't renew my domain name which I assume will be in many years time.


Hotshot2005(Posted 2014) [#9]
What can LUA do?


Yasha(Posted 2014) [#10]
It's a general-purpose programming language, so it can arguably do anything.

The lack of types and the special syntax for building tables makes it very good at tersely extending bigger programs and describing complicated config files, similar to JavaScript. Conversely the "table based" system also lets you come up with weird and wonderful language extensions (e.g. the language has no support for OOP out of the box, but you can build it in totally seamlessly), if you want to play at advanced programming or just need a better DSL.

The syntax is probably the closest you're going to find to BASIC in the modern world, with "function", "local", and "end" instead of braces. Operator overloading is supported (although a bit different from how it would work in a statically typed language).

It supports binary bytecode script files after the fashion of Java classes, so you can pretend not to be delivering plain text scripts if it makes you happy to precompile and hide your work (although TBH these are really easy to decompile).

Finally, as mentioned above, if you use the right engine, it can be really, really fast. Performance-wise it comes in at roughly the "second tier", below C and C++, above BlitzMax and JavaScript, probably similar to Ocaml and C# and so on.

Basically it's a lot like JavaScript in terms of the niche it fills, only smaller/cleaner/faster in most ways.

(Also it is not an acronym: "Lua" is its name.)


Xerra(Posted 2014) [#11]
Lua, for you World of Warcraft players, is also the language the players use to create custom UI modifications. In fact most of the front-end stuff of the game has been written with it interfacing the graphics engine. Along with .xml, of course.


Derron(Posted 2014) [#12]
As we do not have "private" and "public" you cannot just glue lua and blitzmax internal code - you have to adjust the way lua is able to access things.

I have done that using "meta data". By default properties are only "readable" except I have an "rw" added as meta data. To overcome this you could of course also expose Setter-Methods to set property values from LUA.


bye
Ron


PhotonTom(Posted 2014) [#13]
Anyone have any idea how I can get luajit to work nicely with brl.maxlua?
Keep getting a memory access violation in brl.maxlua here:
If lua_pcall( L,0,0,0 ) LuaDumpErr

This is obviously after I've changed Import Pub.Lua to Import zeke.luajit2 and #include <pub.mod/lua.mod/lua-5.1.4/src/lua.h> to #include <zeke.mod/luajit2.mod/LuaJIT-2.0.0/src/lua.h> in lua_object.c


Starkkz(Posted 2014) [#14]
Hello, sticking to the point of LuaJIT, I got the Zeke's LuaJIT module for BlitzMax but when I try to load FFI I get this error.
Lua Error: D:\Escritorio\LuaJIT\sockets.lua:1: module 'ffi' not found:
	no field package.preload['ffi']
	no file '.\ffi.lua'
	no file 'D:\Escritorio\LuaJIT\lua\ffi.lua'
	no file 'D:\Escritorio\LuaJIT\lua\ffi\init.lua'
	no file 'D:\Program Files (x86)\Lua\5.1\lua\ffi.luac'
	no file '.\ffi.dll'
	no file 'D:\Escritorio\LuaJIT\ffi.dll'
	no file 'D:\Escritorio\LuaJIT\loadall.dll'

Everything else works fine. Do you guys know how to activate FFI?


Starkkz(Posted 2014) [#15]
I just realized that the initial release of the FFI module was on the version 2.0.0 beta 6, but this one is beta 4. Has anyone got any idea about how do you install newer versions where the FFI module would work?