🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Lua

Started by
8 comments, last by Hippokrates 21 years ago
When I asked people questions on how to write my own scripting language the always replied that I should rather use something like Lua. So I googled for some Lua tutorials and read them. But I still do not know how to utilize Lua for my game. All the tutorials taught using lua_dostring or lua_dofile etc. but that did not let me know how I can use Lua for my game. I can''t make a game only from print commands...
Im Anfang war die Tat...Faust
Advertisement
I got a lot of good info out of: Game Scripting Mastery by LaMothe

-- Steve --
-- Steve --
It all depends on what exactly you want your scripting system to do. If you want it to draw a box on the screen, you''re going to have to export a function to Lua that allows box-drawing.

Read the Lua manual, available at its website. You''ll find it informative, comprehensive, and very readable.

How appropriate. You fight like a cow.
Like the others said, take a look more at the manual, it''s rather well written.

What you might be having a problem with is just the general concepts of how it works, so I''ll try to summarize, to help get you started.

Basically Lua will do all the work on the scripting side, but in order for it to do anything useful, you need to provide it with functions to call. There''s a few ways to do this - either manually, or you can use a program to generate these "bindings" automatically.

It''s been a while since I did it manually - and it wasn''t too difficult, but it required a bit of understanding of how Lua works. Lua calls are all stack based, which makes it really simple to work with once you understand it, but that can be difficult if you''re new to the whole thing. It all comes down to creating an intermediate function (that''s registered with Lua) that accepts a Lua State variable as it''s ownly parameter, and then from there you use Lua-API call''s to figure out what the script is trying to do. You can then do whatever logic is needed, or call whatever regular C (or C++) functions are needed, and when the function exits, Lua continues executing the script.

An easier way (the one I recommend) is to use a program to generate these binding''s for you. This makes things REALLY simple and straight forward, but it can sometimes limit how much you can customize Lua for your needs (prolly nothing you''d want at moment anyways). For most situations though, this works great. There''s two out there that I know of, from the Link''s page at Lua''s homepage. One is called Tolua, which only works with Lua 4.0 to my knowledge, and then there is SwigLua, which I do not know much about. Tolua is really easy to use - you make a header file that''s very bare, and after running Tolua on it, you''re pretty much ready to use it after adding two or three lines to your program.

Best of luck
quote: Original post by spg
I got a lot of good info out of: Game Scripting Mastery by LaMothe

-- Steve --


That''s not by LaMothe. It''s actually by Alex Varanese. LaMothe is the series editor.

Regardless, I just finished it, and it''s a great freakin book.

I''m in the middle of wrestling with my own scripting language right now, and between Greg Rosenblatt''s amazing tutorials on this site and that book, I think I''ve got it licked.

Of course, I''m doing mine in C++, not C (cuz I''m a massochist)
daerid@gmail.com
there was a intro/tutorial here on ganedev just some time ago (maximum some weeks) which gave a quite good overview how to use lua, and a good starting point for your own stuff

(this article was (on of) the reasons i started with it )


mfg Phreak
--
"Input... need input!" - Johnny Five, Short Circuit.
http://mitglied.lycos.de/lousyphreak/
is Lua capable of talking to a COM object or do you just implement your own function which you then bind to lua ??

Cheers



Jumpman - Under Construction
I seem to recall LuaCOM, or COMLua, or something like that. Check the lua-users.org website for it. But I wouldn''t expose COM interfaces directly, because I think that the interface exposed in a scripting language should be as high-level as possible.

How appropriate. You fight like a cow.
its more of a question if Lua can call a method or change a property of a COM..

Will look into those versions you mentioned.

Jumpman - Under Construction
Have a look at LuaPlus which you can find here:
http://www.workspacewhiz.com/LuaPlus

This distribution does already include LuaCom and samples which show how to use it.



LightBrain website relaunched, BomberFUN only USD 9.99
visit http://www.lightbrain.de

This topic is closed to new replies.

Advertisement