-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from gilzoide/load-string-and-file
Add `load_string` and `load_file` methods to `LuaState`
- Loading branch information
Showing
9 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
extends RefCounted | ||
|
||
|
||
var lua_state | ||
var function | ||
|
||
|
||
func _init(): | ||
lua_state = LuaState.new() | ||
lua_state.open_libraries() | ||
|
||
|
||
func test_load_fail() -> bool: | ||
var result = lua_state.load_file("res://invalid file") | ||
assert(result is LuaError, "load_file with invalid Lua script should return LuaError") | ||
return true | ||
|
||
|
||
func test_load_function() -> bool: | ||
var result = lua_state.load_file("res://gdscript_tests/lua_files/load_file.gd.lua") | ||
assert(result is LuaFunction, "load_file with valid Lua script should return LuaFunction") | ||
assert(result.invoke(1) == 1) | ||
assert(result.invoke(2) == 2) | ||
assert(result.invoke(1, 2, 3) == [1, 2, 3]) | ||
return true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
extends RefCounted | ||
|
||
|
||
var lua_state | ||
var function | ||
|
||
|
||
func _init(): | ||
lua_state = LuaState.new() | ||
lua_state.open_libraries() | ||
|
||
|
||
func test_load_fail() -> bool: | ||
var result = lua_state.load_string("this is an invalid Lua script") | ||
assert(result is LuaError, "load_string with invalid Lua script should return LuaError") | ||
return true | ||
|
||
|
||
func test_load_function() -> bool: | ||
var result = lua_state.load_string("return ...") | ||
assert(result is LuaFunction, "load_string with valid Lua script should return LuaFunction") | ||
assert(result.invoke(1) == 1) | ||
assert(result.invoke(2) == 2) | ||
assert(result.invoke(1, 2, 3) == [1, 2, 3]) | ||
return true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
return ... |