Heavy scripting
I need to find a scripting language that's
a) REALLY simple (I only need it to support functions, no OO or anything, really)
b) easy to export C functions to (pretty common, I assume)
c) interruptable (as soon as the script gives the game an action to perform, it should be 'halted' until the next turn, when it should resume. so a script that says "move forward; move forward;" would act on moving forwad once, then be suspended until it's next turn and then it moves again.)
d) very lightweight (I want to have up to 1000 of these scripts running at once (well, one at a time... while the rest are suspended))
Anyone know of such a language? before I go write my own custom language for this thing?
I'm not really sure what you mean by C, do you mean the script can explicitly yield, or do you mean automatically yields after every statement?
Either way it sounds like you want co-routine support, and I can't think of any language with both A and C.
Either way it sounds like you want co-routine support, and I can't think of any language with both A and C.
Lua really sounds almost exactly like what you want. Many people don't like its syntax (or even semantics), but it is certainly pretty lightweight and easily embeddable.
Lua does not have native OO per-se, but can simulate OO in a useful way using function tables (which behave a lot like object if you look at them in the right light).
As far as "interruptable" is concerned - this is exactly what lua coroutines do.
1000 coroutines running at once? I see no problems other than memory usage, and I guess that's dependent on what you happen to have on the lua stack at the time (which must get stored in the coroutine).
I've no idea how easy it is to export C functions to Lua, I've always used luabind (which is a C++ library, but can still be used to export plain functions, not just objects).
Mark
Lua does not have native OO per-se, but can simulate OO in a useful way using function tables (which behave a lot like object if you look at them in the right light).
As far as "interruptable" is concerned - this is exactly what lua coroutines do.
1000 coroutines running at once? I see no problems other than memory usage, and I guess that's dependent on what you happen to have on the lua stack at the time (which must get stored in the coroutine).
I've no idea how easy it is to export C functions to Lua, I've always used luabind (which is a C++ library, but can still be used to export plain functions, not just objects).
Mark
by interruptable, i mean that when the scripts calls a function that takes an action within the game world, that function can (for instance) set a flag that makes the interpreter stop there, for now (will resume when the interpreter is called again)
does that make sense?
I'm goign to check out lua's coroutines. not sure if this is what I want jsut yet...
does that make sense?
I'm goign to check out lua's coroutines. not sure if this is what I want jsut yet...
I'd recommend Lua for this, too, although if you really only need to support running a list of functions, and you're definitely not going want anything more later on, then it'd be fairly easy to just write your own system for it.
Exporting C functions to lua is very simple. Making the script halt from a C function is as easy as:
John B
Exporting C functions to lua is very simple. Making the script halt from a C function is as easy as:
int script_move_forward(lua_State *lua){ /* code to initiate the movement */ return lua_yield(lua, 0);}
John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Quote: Original post by JohnBSmallI was just looking at the lua docs and saw this under threads and went "yureka!" One simple additional quesiton: this is a lua-internal thread, right? it doesn't do anything with actual OS-level threads....right?
Exporting C functions to lua is very simple. Making the script halt from a C function is as easy as:
*** Source Snippet Removed ***
Quote: Original post by C-Junkie
I was just looking at the lua docs and saw this under threads and went "yureka!" One simple additional quesiton: this is a lua-internal thread, right? it doesn't do anything with actual OS-level threads....right?
Correct.
John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Another small comment: Integration with Lua is very easy, but it's also tedious; if you're really stuck with pure C, then the best you can get is probably writing helper macros and functions for yourself.
Edit: actually... that's not entirely true, look at the Lua wiki links page, something like toLua might help.
If your host app is in C++, you've got more options - personally, I'm actually using LuaPlus which is a based on Lua (some changes to the C internals, plus a lot of C++ wrapping) and is very easy to integrate. As markr mentioned, there's also luabind which is a C++ wrapping system built on Lua (no changes to the core, unlike LuaPlus). I haven't used it myself, but I expect it's as good or better than LuaPlus for integration with C++ code.
John B
Edit: actually... that's not entirely true, look at the Lua wiki links page, something like toLua might help.
If your host app is in C++, you've got more options - personally, I'm actually using LuaPlus which is a based on Lua (some changes to the C internals, plus a lot of C++ wrapping) and is very easy to integrate. As markr mentioned, there's also luabind which is a C++ wrapping system built on Lua (no changes to the core, unlike LuaPlus). I haven't used it myself, but I expect it's as good or better than LuaPlus for integration with C++ code.
John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
LUA is teh evil!
J/K
Anyway, you might want to use Small, has all your requirements, and it's easier to embed than LUA.
J/K
Anyway, you might want to use Small, has all your requirements, and it's easier to embed than LUA.
Quote: Original post by Raduprv
LUA is teh evil!
J/K
Anyway, you might want to use Small, has all your requirements, and it's easier to embed than LUA.
I had a look at Small a while ago... it didn't look easier to embed. Maybe that's just me though. Also, it looked like it normally requires pre-compiled scripts, instead of letting you give it either (compiled or source)... not a big thing, but having another build step before you can test something isn't particularly nice (imho). Pros and cons I guess.
I could be mis-remembering about the compile requirement though... I was looking at other languages at the same time, so I might be getting them mixed up.
John B
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement