/
PLUGIN_API.txt
180 lines (141 loc) · 4.07 KB
/
PLUGIN_API.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
PLUGIN API FILE
Table of contents: (Use the search function Ctrl+F)
* API File notes
* Function reference
* Return values
* Hello world 2
* More functions
* Using C
API File notes
================
< This line is a command input
> This line is an output text
Lua is case-sensitive, so "MonkeyFunc" is not "monkeyfunc"!
Function reference
====================
Variables
-----------
L.online
^ Number of online players
L.nick
^ Chatter's nickname
L.hostmask
^ Chatter's hostmask
Functions
-----------
# misc_helpers.lua (automatically loaded)
dump(object)
^ Analyzes and outputs a table and its contents as a string
fromFancy("<formatted number>")
^ Formats ugly number to fancy ("1k" -> 1000, "1 m" -> 0.001)
toFancy(number, [digits])
^ Converts fancy number to ugly (1000 -> "1k", 0.001 -> "1m")
^ digits: Optional, describes the decimal digits
c("<text>")
^ Returns a for chat used, highlighted text value
getUserObject("<name>")
^ Searchs a currently online user in the channel (case insensitive)
^ Returns { nick=?, hostmask=? } or nil if not found
math.round(number, [digits])
^ Rounds the number
^ digits: Optional, describes the decimal digits
math.sign(number, [tolerance])
^ Gets the sign of a number
^ tolerance: Optional, must be a positive number
random(min, max, [decimal_output])
^ Returns a random number between and including [min] and [max - 1]
^ decimal_output: Returns decimal places aswell when set to true
string:split("<delimiter>")
^ Splits a string into an array, using the delimiter character(s)
string:trim()
^ Removes beginning and tailing spaces
table.copy(table)
^ Copies a table to remove its reference
# complex.lua (automatically loaded)
Complex([real], [imaginary])
^ Creates a new complex calculating class
^ real, imaginary: Optional, will be set to zero otherwise
:add(real, imaginary)
:add(Complex_object)
:addPolar(length, angle)
^ Adds polar value to the real and imaginary axis (degrees) [buggy!]
:addReal(amount)
:addImag(amount)
:length()
^ Length of the polar hypotenuse / absolute value
:angle()
^ Angle in the polar system (degrees)
:tostring()
:topolar()
Return values
===============
"return" does only output a chat message when it's called from the chat itself:
function getHello()
return "Hello world"
end
< $ getHello()
> ME: <no return text>
< $ return getHello()
> Hello world
Hello world 2
===============
Using "print" to output a text automatically:
function getHello()
return "Hello"
end
function sayHi()
-- Combine "Hello" and " world"
print(getHello() .." world")
end
< $ sayHi()
> Hello world
Another (rather ugly) variant:
function sayHi()
-- Output "Hello" and "world" seperately
-- spaces in between are added autmatically
print("Hello")
print("world")
end
< $ sayHi()
> Hello world
More functions
================
This API file only contains the must-have functions to start scripting.
Link to all documented functions in this bot:
https://github.com/SmallJoker/NyisBot/blob/master/help.txt
Using C
=========
C modules can be loaded in Lua, which is executed by C#.
So this has some speed loss and is only recommended for heavy calculations.
Add the LuaJIT path to the include directories of your project then you
might want to use this prepared template to begin coding:
-----------------------------
#include "lua.h"
#include "lauxlib.h"
#ifdef _WIN32
# define EXPORT __declspec(dllexport)
#else
# define EXPORT LUALIB_API
#endif
static int l_myCoolFunction(lua_State *L)
{
// You can rename this function and copypaste it as much you want.
// Just don't forget to register it in "luaopen_<PLUGINNAME>_"
lua_pushinteger(L, 1234); // See Lua C reference for more functions
return 1; // Number of return values
}
static int luaopen_<PLUGINNAME>_(lua_State *L)
{
lua_pushcfunction(L, l_myCoolFunction);
lua_setglobal(L, "myCoolFunction");
return 1;
}
EXPORT int luaopen_<PLUGINNAME>(lua_State *L)
{
return luaopen_<PLUGINNAME>_(L);
}
EXPORT int luaopen_<PLUGINNAME>_safe(lua_State *L)
{
return luaopen_LuaPlugin_(L);
}
-----------------------------