Jump to content


Photo

Parsing %{command.data} in Lua


  • Please log in to reply
3 replies to this topic

#1 Trinovi

Trinovi

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 01 October 2011 - 08:26 PM

Hello,

This is probably a question answered elsewhere here, but I can't seem to find exactly what I'm looking for, which is either:

1.) A simple way to take space-separated command data strings and assign them to variables in a Lua script

or, barring that,

2.) An easy way to store my own %{command.data} parsing function in global space, so that any of my Lua scripts may call it, as opposed to my having to define such a function within each script.

Had Lua a split() or explode() or similar string manipulation function, I would just pass %{command.data} to that, but sadly it does not.

Either of these solutions would be great for me. (I would like to know how to do both, if both possibilities exist!)

If it isn't clear what I'm after, here's an example.

If entered into the command window, the command 'gbag food 3' would send to the world, 'get all food from bag 3'.

pseudocode:

gbag(item, bagNumber) {
Atlantis:sendText(world, 'get ' .. item .. ' from bag ' .. bagNumber);
}

How do I turn %{command.data}, 'bag 3' into item='bag', bagNumber=3 ?

Thanks for any help anyone can provide.

T

#2 wombat

wombat

    Advanced Member

  • Members
  • PipPipPip
  • 321 posts

Posted 02 October 2011 - 03:59 PM

I don't use Lua, but I would assume you can put your own .lua library file in ~/Library/Atlantis/Scripts/ and call functions the same way you do the Atlantis functions.

#3 Trinovi

Trinovi

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 05 October 2011 - 09:31 PM

Thanks, Wombat. I assume something like that is possible, too, but it doesn't appear that *.lua gets loaded when the application is run, otherwise I would expect functions like MyFunctions:foo(), defined in ~/Library/Atlantis/Scripts/MyFunctions.lua as...

function MyFunction:foo()
Atlantis:sendText(AtlantisState['world.name'], 'say foo');
end

...to be callable in my aliases in the same way as Atlantis:<functions> are callable. Unfortunately, this isn't the case. Here is the error string:

%% Error: [string "?"]:1: attempt to call method 'foo' (a nil value)

My alias is simply:

MyFunctions:foo()

Any tips on how to load up my own libraries either in runtime or when launching the application? I'll dig around the other threads for an answer, but if anyone can help out, I'd be grateful.

T

#4 Trinovi

Trinovi

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 05 October 2011 - 09:55 PM

Moving my lib into a directory under the lua path, and then requiring it in my alias, works, but it seems like an inelegant way to do this.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users