New to lua... few questions

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

New to lua... few questions

Kevin Vandenborne
Hello all, for an application i'm writting i want to use lua as the script language.

I want to be able to load and unload scripts. lets say i have a window form with a editbox and the user can type SCRIPTLOAD <scriptName> and SCRIPTEND <scriptName> and have multieple scripts running at once. Would this be possible? anyone have a example howto?

Second question what does happen if ya reload a script? Does it update the functions if its allready in the memmory? I really only have experience with PHP. and in PHP it would prompt a error if the function allready exists.

I'm using c#  with Tao.Lua to get full access to the API

Regards...



Reply | Threaded
Open this post in threaded view
|

Re: New to lua... few questions

Asko Kauppi

Your message may well be left with only a few -if any- replies, due to too scarce details, and lazy use of language. You are a native English writer and addressing thousands of people, don't you think you should brush up? :)

Now, to the point (below).


Kevin Vandenborne kirjoitti 31.10.2006 kello 19.50:

Hello all, for an application i'm writting i want to use lua as the script language.

I want to be able to load and unload scripts. lets say i have a window form with a editbox and the user can type SCRIPTLOAD <scriptName> and SCRIPTEND <scriptName> and have multieple scripts running at once. Would this be possible? anyone have a example howto?

What exactly do you mean by "multiple scripts running at once"? You can use either multiple lua_States (and OS-level threading) or Lua's coroutine approach, which shares a state and is kind of like old non- preemptive multitasking. The reference manual tells the details of the latter.

Ask first, should the multiple scripts have how much to do with each other. If none, use separate states. If they do, you need to make a choice. The whole problem area remains fuzzy to me from your description. Sorry. :)

Normally, people don't "unload" scripts. It's easy to start with a completely clean lua_State if needed. Why exactly would you unload, and what exactly do you mean by it?


Second question what does happen if ya reload a script? Does it update the functions if its allready in the memmory? I really only have experience with PHP. and in PHP it would prompt a error if the function allready exists.

Functions are just names in Lua. Of the little I know it, I place PHP closer to C and not as a real real scripting language. Avoid making too much parallels between the two.

print(print)	-> function
print=1
print(print)	-> will fail, since 'print' is now 1 and you cannot call 1

Functions are there, but they are not bound with a fixed name. In a way, all functions in Lua are anonymous.

Welcome to the world of Lua; I wish you get the help and notice the language serving you tremendously. :)
-asko



I'm using c#  with Tao.Lua to get full access to the API

Regards...




Reply | Threaded
Open this post in threaded view
|

Re: New to lua... few questions

Kevin Vandenborne
Well, The app i'm currently trying to make is a log parser for online games, Mainly to find certain text matched and alarm the user if found

Now i want to use lua to allow to make easy scripts to create triggers to find.

Example test.lua

trigger("find this in the game log file, "Test_function"); the search phase and call Test_function when found

function Test_function() // Do this
   speak("test");
end

Basicly on script load C# will add the triggers into a arrayList wich the app will loop trough and if a match happens it calls the lua function Test_function

Now i want to be able to load new scripts while the program is running and to be able to unload scripts.

Sorry for my bad english =p



Reply | Threaded
Open this post in threaded view
|

Re: New to lua... few questions

Kevin Vandenborne
In reply to this post by Asko Kauppi
Well, The app i'm currently trying to make is a log parser for online games, Mainly to find certain text matched and alarm the user if found

Now i want to use lua to allow to make easy scripts to create triggers to find.

Example test.lua

trigger("find this in the game log file, "Test_function"); the search phase and call Test_function when found

function Test_function() // Do this
   speak("test");
end

Basicly on script load C# will add the triggers into a arrayList wich the app will loop trough and if a match happens it calls the lua function Test_function

Now i want to be able to load new scripts while the program is running and to be able to unload scripts.

Sorry for my bad english =p



Reply | Threaded
Open this post in threaded view
|

Re: New to lua... few questions

Fabian Peña
/Second question what does happen if ya reload a script? Does it update
the functions if its allready in the memmory? I really only have
experience with PHP. and in PHP it would prompt a error if the function
allready exists.
/


If you  want some help in spanish speak , please contact me. :-)



Reply | Threaded
Open this post in threaded view
|

Re: New to lua... few questions

Asko Kauppi
In reply to this post by Kevin Vandenborne

This all sounds like very basic Lua stuff to me. Apart from the script unloading but taken you have:

  filters= {
	["find this in the game log file"]=	function() speak "test" end,
	}

you can:
  filters["find this in the game log file"]= nil

..and that function is nowhere to be reached any more.

This is where I started my journey to Lua (at 4.0 time):
http://www.lua.org/manual/


Kevin Vandenborne kirjoitti 31.10.2006 kello 22.33:

Well, The app i'm currently trying to make is a log parser for online games, Mainly to find certain text matched and alarm the user if found

Now i want to use lua to allow to make easy scripts to create triggers to find.

Example test.lua

trigger("find this in the game log file, "Test_function"); the search phase and call Test_function when found

function Test_function() // Do this
   speak("test");
end

Basicly on script load C# will add the triggers into a arrayList wich the app will loop trough and if a match happens it calls the lua function Test_function

Now i want to be able to load new scripts while the program is running and to be able to unload scripts.

Sorry for my bad english =p