From 0b55e12f7f9fc98d22b2bead44d064af8c3f92c4 Mon Sep 17 00:00:00 2001 From: sanine Date: Sat, 4 Sep 2021 12:24:57 -0500 Subject: remove va_nargs.h and begin adding examples --- examples/argument_parsing/#argument_parsing.c# | 28 +++++++++++++++++++++++++ examples/argument_parsing/argument_parsing.c | 23 ++++++++++++++++++++ examples/table_creation/a.out | Bin 0 -> 26712 bytes examples/table_creation/table_creation.c | 28 +++++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 examples/argument_parsing/#argument_parsing.c# create mode 100644 examples/argument_parsing/argument_parsing.c create mode 100755 examples/table_creation/a.out create mode 100644 examples/table_creation/table_creation.c (limited to 'examples') diff --git a/examples/argument_parsing/#argument_parsing.c# b/examples/argument_parsing/#argument_parsing.c# new file mode 100644 index 0000000..38309db --- /dev/null +++ b/examples/argument_parsing/#argument_parsing.c# @@ -0,0 +1,28 @@ +#include + +int demo(lua_State *L) +{ + lua_Integer i; + lua_Number n; + char *string; + hs_parse_args(L, hs_int(i), hs_num(n), hs_str(string)); + printf("received %d, %f, and %s\n", i, n, string); + return 0; +} + +int main() +{ + lua_State *L = luaL_newstate(); + luaL_openlibs(L); + + lua_pushcfunction(L, demo); + lua_setglobal(L, "demo"); + + luaL_dostring("demo(12, 34.4, 'hi there!')"); + return 0; +} + +grindr +hinge +bumble +lex diff --git a/examples/argument_parsing/argument_parsing.c b/examples/argument_parsing/argument_parsing.c new file mode 100644 index 0000000..11a48f4 --- /dev/null +++ b/examples/argument_parsing/argument_parsing.c @@ -0,0 +1,23 @@ +#include + +int demo(lua_State *L) +{ + lua_Integer i; + lua_Number n; + char *string; + hs_parse_args(L, hs_int(i), hs_num(n), hs_str(string)); + printf("received %ld, %f, and %s\n", i, n, string); + return 0; +} + +int main() +{ + lua_State *L = luaL_newstate(); + luaL_openlibs(L); + + lua_pushcfunction(L, demo); + lua_setglobal(L, "demo"); + + luaL_dostring(L, "demo(12, 34.4, 'hi there!')"); + return 0; +} diff --git a/examples/table_creation/a.out b/examples/table_creation/a.out new file mode 100755 index 0000000..0e506e3 Binary files /dev/null and b/examples/table_creation/a.out differ diff --git a/examples/table_creation/table_creation.c b/examples/table_creation/table_creation.c new file mode 100644 index 0000000..42088c6 --- /dev/null +++ b/examples/table_creation/table_creation.c @@ -0,0 +1,28 @@ +#include + +int main() +{ + lua_State *L = luaL_newstate(); + luaL_openlibs(L); + + /* create the table + * { "one"=1, "two"=2, "half"=0.5, "runme"=[some function] } + */ + luaL_dostring(L, + "return function(self) \n" \ + "print(self.one)\n" \ + "print(self.two)\n" \ + "print(self.half)\n" \ + "end"); + int func_index = lua_gettop(L); + + hs_create_table(L, + hs_str_int("one", 1), + hs_str_int("two", 2), + hs_str_num("half", 0.5f), + hs_str_func("runme", func_index)); + lua_setglobal(L, "runnable"); + + luaL_dostring(L, "runnable:runme()"); + return 0; +} -- cgit v1.2.1