- Joined
- Nov 7, 2014
- Messages
- 571
Lispy Repl and ~5K of symbols
The 'lispy-repl.lua' file allows one to evaluate Lisp-style expressions (because they are easy to parse).
The code for the "Repl" detects strings that player red typed and begin with '$', it then evaluates them and prints the result (in a somewhat friendlier way than the 'print' function).
The 'empty-map-symbols.txt' file is a list of symbols in the "global" scope (names of constants, variables, functions, built-in Lua "stuff") of an "empty" map that uses Lua rather than Jass. You could try to print some of them (e.g: '$ _VERSION').
The 'lispy-repl.lua' file allows one to evaluate Lisp-style expressions (because they are easy to parse).
Code:
(CreateUnit (Player 0) <hfoo> 0.0 0.0 270.0) -- creates a footman for player red
(table.pack 1 0x02 'three' #t nil ['this' 'is' 'a' 'list'])
(+ 1 2) -- the first "thing" inside of '(...)' must be a function or an operator
The code for the "Repl" detects strings that player red typed and begin with '$', it then evaluates them and prints the result (in a somewhat friendlier way than the 'print' function).
Lua:
local function on_input()
local substr = string.sub
local s = GetEventPlayerChatString()
if '$' == substr(s, 1, 1) then
local expr = substr(s, 2)
local ret, err = lispy.eval(expr)
if err ~= nil then
print('error: ' .. err)
else
print_val(ret)
end
end
end
local function entry_point()
local t = CreateTrigger()
TriggerRegisterPlayerChatEvent(t, Player(0), '', '')
TriggerAddAction(t, on_input)
end
The 'empty-map-symbols.txt' file is a list of symbols in the "global" scope (names of constants, variables, functions, built-in Lua "stuff") of an "empty" map that uses Lua rather than Jass. You could try to print some of them (e.g: '$ _VERSION').