aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/ansi_c
diff options
context:
space:
mode:
authorGravatar mitchell <70453897+667e-11@users.noreply.github.com>2015-10-22 13:39:47 -0400
committerGravatar mitchell <70453897+667e-11@users.noreply.github.com>2015-10-22 13:39:47 -0400
commit9ab96d83b72e058d66a6eb2b109cea574d87e031 (patch)
treec392c70a9db56c6a46c240bc75e85bf1d7026b2d /modules/ansi_c
parent5caed0d5331c823ad74d2c443b9e0f8702349520 (diff)
Refactored 'ansi_c' and 'lua' modules' snippets.
Also removed command for auto-'end' insertion of Lua control structures since snippets are now favored.
Diffstat (limited to 'modules/ansi_c')
-rw-r--r--modules/ansi_c/init.lua96
1 files changed, 25 insertions, 71 deletions
diff --git a/modules/ansi_c/init.lua b/modules/ansi_c/init.lua
index 50b3880f..2a0b793d 100644
--- a/modules/ansi_c/init.lua
+++ b/modules/ansi_c/init.lua
@@ -102,82 +102,36 @@ keys.ansi_c = {
-- Snippets.
+if type(snippets) == 'table' then
---
-- Table of C-specific snippets.
-- @class table
-- @name _G.snippets.ansi_c
-if type(snippets) == 'table' then
snippets.ansi_c = {
- -- Lua snippets
- lc = 'lua_call(%1(L), %2(nargs), %3(nresults))',
- lcs = 'lua_checkstack(%1(L), %2(1))',
- lf = 'static int %1(func)(lua_State *%2(L)) {\n\t%0\n\treturn %3(0);\n}',
- lgf = 'lua_getfield(%1(L), %2(-1), %3(field))',
- lgg = 'lua_getglobal(%1(L), %2(global))',
- lgmt = 'lua_getmetatable(%1(L), %2(-1))',
- lgt = 'lua_gettable(%1(L), %2(-2))',
- ltop = 'lua_gettop(%1(L))',
- lib = 'lua_isboolean(%1(L), %2(-1))',
- licf = 'lua_iscfunction(%1(L), %2(-1))',
- lif = 'lua_isfunction(%1(L), %2(-1))',
- lilu = 'lua_islightuserdata(%1(L), %2(-1))',
- linil = 'lua_isnil(%1(L), %2(-1))',
- linone = 'lua_isnone(%1(L), %2(-1))',
- linonen = 'lua_isnoneornil(%1(L), %2(-1))',
- lin = 'lua_isnumber(%1(L), %2(-1))',
- lis = 'lua_isstring(%1(L), %2(-1))',
- lit = 'lua_istable(%1(L), %2(-1))',
- liu = 'lua_isuserdata(%1(L), %2(-1))',
- llen = 'lua_len(%1(L), %2(-1))',
- lrlen = 'lua_rawlen(%1(L), %2(-1))',
- lnt = 'lua_newtable(%1(L))',
- lnu = '(%3 *)lua_newuserdata(%1(L), %2(sizeof(%3(struct))))',
- ln = 'lua_next(%1(L), %2(-2))',
- lpc = 'lua_pcall(%1(L), %2(nargs), %3(nresults), %4(msgh))',
- lpop = 'lua_pop(%1(L), %2(1))',
- lpb = 'lua_pushboolean(%1(L), %2(bool))',
- lpcc = 'lua_pushcclosure(%1(L), %2(cfunc), %3(nvalues))',
- lpcf = 'lua_pushcfunction(%1(L), %2(cfunc))',
- lpi = 'lua_pushinteger(%1(L), %2(integer))',
- lplu = 'lua_pushlightuserdata(%1(L), %2(pointer))',
- lpnil = 'lua_pushnil(%1(L))',
- lpn = 'lua_pushnumber(%1(L), %2(number))',
- lps = 'lua_pushstring(%1(L), %2(string))',
- lpls = 'lua_pushlstring(%1(L), %2(string), %3(len))',
- lpv = 'lua_pushvalue(%1(L), %2(-1))',
- lrg = 'lua_rawget(%1(L), %2(-2))',
- lrgi = 'lua_rawgeti(%1(L), %2(-2), %3(1))',
- lrs = 'lua_rawset(%1(L), %2(-3))',
- lrsi = 'lua_rawseti(%1(L), %2(-2), %3(1))',
- lr = 'lua_register(%1(L), %2(name), %3(cfunc))',
- lsf = 'lua_setfield(%1(L), %2(-2), %3(field))',
- lsg = 'lua_setglobal(%1(L), %2(global))',
- lsmt = 'lua_setmetatable(%1(L), %2(-2))',
- lst = 'lua_settable(%1(L), %2(-3))',
- ltb = 'lua_toboolean(%1(L), %2(-1))',
- lti = 'lua_tointeger(%1(L), %2(-1))',
- ltn = 'lua_tonumber(%1(L), %2(-1))',
- ltls = 'lua_tolstring(%1(L), %2(-1), &%3(int))',
- lts = 'lua_tostring(%1(L), %2(-1))',
- ltu = '(%3 *)lua_touserdata(%1(L), %2(-1))',
- lt = 'lua_type(%1(L), %2(-1))',
- llac = 'luaL_argcheck(%1(L), %2(expr), %3(1), %4(extramsg))',
- llci = 'luaL_checkinteger(%1(L), %2(1))',
- llcl = 'luaL_checklong(%1(L), %2(1))',
- llcls = 'luaL_checklstring(%1(L), %2(1), &%3(int))',
- llcn = 'luaL_checknumber(%1(L), %2(1))',
- llcs = 'luaL_checkstring(%1(L), %2(1))',
- llcu = '(%4 *)luaL_checkudata(%1(L), %2(1), %3(mt_name))',
- llerr = 'luaL_error(%1(L), %2(message)%3(, %4(arg)))',
- llgmt = 'luaL_getmetatable(%1(L), %2(mt_name))',
- llnmt = 'luaL_newmetatable(%1(L), %2(mt_name))',
- lloi = 'luaL_optinteger(%1(L), %2(1), %3(default))',
- llol = 'luaL_optlong(%1(L), %2(1), %3(default))',
- llon = 'luaL_optnumber(%1(L), %2(1), %3(default))',
- llos = 'luaL_optstring(%1(L), %2(1), %3(default))',
- llref = 'luaL_ref(%1(L), %2(LUA_REGISTRYINDEX))',
- llsmt = 'luaL_setmetatable(%1(L), %2(mt_name))',
- lluref = 'luaL_unref(%1(L), %2(LUA_REGISTRYINDEX), %3(ref))',
+ func = '%1(int) %2(name)(%3(args)) {\n\t%0\n\treturn %4(0);\n}',
+ vfunc = 'void %1(name)(%2(args)) {\n\t%0\n}',
+ ['if'] = 'if (%1) {\n\t%0\n}',
+ eif = 'else if (%1) {\n\t%0\n}',
+ ['else'] = 'else {\n\t%0\n}',
+ ['for'] = 'for (%1; %2; %3) {\n\t%0\n}',
+ ['fori'] = 'for (%1(int) %2(i) = %3(0); %2 %4(<) %5(count); %2%6(++)) {\n'..
+ '\t%0\n}',
+ ['while'] = 'while (%1) {\n\t%0\n}',
+ ['do'] = 'do {\n\t%0\n} while (%1);',
+ sw = 'switch (%1) {\n\tcase %2:\n\t\t%0\n\t\tbreak;\n}',
+ case = 'case %1:\n\t%0\n\tbreak;',
+
+ st = 'struct %1(name) {\n\t%0\n};',
+ td = 'typedef %1(int) %2(name_t);',
+ tds = 'typedef struct %1(name) {\n\t%0\n} %1%2(_t);',
+
+ def = '#define %1(name) %2(value)',
+ inc = '#include "%1"',
+ Inc = '#include <%1>',
+ pif = '#if %1\n%0\n#endif',
+
+ main = 'int main(int argc, const char **argv) {\n\t%0\n\treturn 0;\n}',
+ printf = 'printf("%1(%s)\\n", %2);',
}
end